package team3132.utils;

/**
 * Create a wrapper around an optional value stored in the network table.
 * If the value is not present in the table, the default value is returned.
 */
public class OptionalNetworkTableValue extends NetworkTableValue {

  private final String defaultValue;

  public OptionalNetworkTableValue(String key, String defaultValue) {
    super(key, false);
    this.defaultValue = defaultValue;
  }

  public double getDoubleValue() {
    if (isValueSet()) {
      return super.getDoubleValue();
    } else {
      return Double.valueOf(defaultValue).doubleValue();
    }
  }

  public int getIntValue() {
    if (isValueSet()) {
      return super.getIntValue();
    } else {
      return Double.valueOf(defaultValue).intValue();
    }
  }

  public String getStringValue() {
    if (isValueSet()) {
      return super.getStringValue();
    } else {
      return defaultValue;
    }
  }
}
